package com.hx.haowumall.haowumallorder.web;

import com.alipay.api.AlipayApiException;
import com.hx.haowumall.haowumallorder.config.AlipayTemplate;
import com.hx.haowumall.haowumallorder.service.OrderService;
import com.hx.haowumall.haowumallorder.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    /**
     * 1、将支付页让浏览器展示
     * 2、支付成功以后，我们要跳到用户的订单列表页
     * */
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {

        PayVo payVo = orderService.getOrderPayInfo(orderSn);
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);

        return pay;
    }
}
